package com.victor.netty.fourexample;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;

/**
 *  心跳检测
 * Created by DJJ on 2019/5/31.
 * 在tcp中,如果手机和服务器建立了连接,但手机开启飞行模式,连接是不会断开的 不会调用handlerRemoved
 *
 */
public class MyServer {

    public static void main(String[] args) throws InterruptedException {
        EventLoopGroup boosGroup=new NioEventLoopGroup();//也叫做parent
        EventLoopGroup wokerGroup=new NioEventLoopGroup();//也叫做child

        try {
            ServerBootstrap serverBootstrap=new ServerBootstrap();
            serverBootstrap.group(boosGroup,wokerGroup).channel(NioServerSocketChannel.class)
                    .handler(new LoggingHandler(LogLevel.INFO))//handler是对boss处理的
                    .childHandler(new MyServertInitializer());//childHandler 是对woker 处理的
            ChannelFuture channelFuture = serverBootstrap.bind(8899).sync();
            channelFuture.channel().closeFuture().sync();
        } finally {
            boosGroup.shutdownGracefully();
            wokerGroup.shutdownGracefully();
        }
    }
}
